#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "util.h"

char *alloc_string(int size)
{
	return (char*)malloc(size);
}

char *new_string(char *str)
{
	char *ret;
	ret = (char *)malloc(strlen(str) + 1);
	strcpy(ret, str);
	
	return ret;	
}

void free_string(char *str)
{
	free(str);
}

void string_split(char *src, char *interval, struct list_head *head)
{
	char *find;
	struct strlist	*temp;
	char *str;

	str = new_string(src);
	find =strtok(str, interval);
	while(find != NULL)
	{
		temp = (struct strlist *)malloc(sizeof(struct strlist));	
		temp->str = new_string(find);
		list_add_tail(&temp->list, head);	
		find = strtok(NULL, interval);
	}
	free_string(str);
}

void free_strlist(struct list_head *head)
{
	struct strlist *slist;

	list_for_each_entry(slist, head, list)
	{
		free_string(slist->str);		
	} 
}

